package com.learn.controller;

import com.learn.domain.User;
import com.learn.repository.UserRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by weijianxing on 3/29/15.
 */
@Controller
public class HelloWorldController {

    @Autowired
    private UserRepo userRepo;

    @RequestMapping(value = "/hello")
    public ModelAndView hello(String name, ModelAndView modelAndView) {
        modelAndView.addObject("name", name);
        modelAndView.setViewName("hello");
        return modelAndView;
    }

    @RequestMapping(value = "confirmLogin.do")
    public
    @ResponseBody
    String confirmLogin(String username, String password) {
        User user =
                userRepo.findUserByUserName(username);
        if (user == null) {
            return "用户不存在";
        }

        if (user.getPassword().equals(password) == false) {
            return "密码错误";
        }

        return "成功";
    }
}
